<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>通知浏览记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body>

<!--查询参数的表单-->
<form class="layui-form layui-form-pane layui-margin-3 layui-anim layui-anim-downbit">

    <div class="layui-form-item">

        <div class="layui-inline">
            <label class="layui-form-label">通知编号</label>
            <div class="layui-input-block">
                <input type="number" name="what" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">用户编号</label>
            <div class="layui-input-block">
                <input type="number" name="who" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <button class="layui-btn" lay-submit lay-filter="toDo">搜索浏览记录</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<!--数据表格-->
<div class="layui-margin-3 layui-anim layui-anim-upbit">
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<script src="/layui/layui.js"></script>
<script>

    layui.use(['table', 'form', 'layer'], function () {
        let table = layui.table;
        let form = layui.form;
        let layer = layui.layer;

        // 搜索按钮事件
        form.on('submit(toDo)', function (data) {
            let field = data.field; // 获取表单字段值

            table.reload('test', {  // 表格数据重载
                where: {
                    'what': field.what,
                    'who': field.who
                }
            });
            return false; // 阻止默认 form 跳转
        });

        // 创建渲染实例
        table.render({
            elem: '#test',
            url: '/getAllBrowseData',
            page: true,
            limit: 15,
            limits: [15, 30, 50],
            cols: [
                [
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID'},
                    {field: 'notice.id', title: '通知编号', templet: '<div><span class="layui-badge layui-bg-gray">{{= d.notice.id }}</span></div>'},
                    {field: 'notice.title', title: '通知标题', templet: '{{= d.notice.title }}'},
                    {field: 'user.id', title: '用户编号', templet: '<div><span class="layui-badge layui-bg-gray">{{= d.user.id }}</span></div>'},
                    {field: 'user.name', title: '用户昵称', templet: '{{= d.user.name }}'},
                    {field: 'notice.when', title: '通知发布时间', templet: '{{= d.notice.when }}'},
                    {field: 'when', title: '用户浏览时间'}
                ]
            ],
            error: function (res, msg) {
                console.log(res, msg)
            }
        });

        // 行单击事件
        table.on('row(test)', function (obj) {
            layer.msg('点击：' + obj.data.id);
        });
    });
</script>
</body>
</html>